/**
 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { PI, E } from "std/math/consts";

{%- for number in item.init_object_param_list.keys() %}
const TEST_DATA_{{.number|upper}} : {{.item. init_object_data_types[number]}} = {{.item. init_object_param_list[number]}};
{%- endfor %}
const TEST_DATA_EXPECTED : {{.item.expected_data_type}} = {{.item.expected_test_data}};

function main(): int {
  let expectedDataIdx : long = 0
  let passedCounter : long = 0;
  let expectedPassedTest : int = 0;
{%- for _ in item.init_object_param_list.keys() %}
  arktest.assertEQ(TEST_DATA_EXPECTED.length, TEST_DATA_{{.item.init_object_param_list.keys()|first|upper}}.length)
{%- endfor %}
{%- if item.init_object_default is defined %}
  expectedPassedTest = TEST_DATA_EXPECTED.length + 1;
{%- else %}
  expectedPassedTest = TEST_DATA_EXPECTED.length;
{%- endif %}
{%- if item.init_object_default is defined %}
  if (testDefaultConstructor()) {
    console.print("PASSED DEFAULT CONSTRUCTOR ");
    passedCounter++;
  } else {
    console.print("FAILED DEFAULT CONSTRUCTOR ")
  }
{%- endif %}
for (let i = 0; i < TEST_DATA_{{.item.init_object_param_list.keys()|first|upper}}.length; i++) {
    if (testConstructor(i)) {
    passedCounter++;
    console.println()
    console.print("PASSED");
    } else {
      console.print("FAILED")
    }
    console.println();
  }
  arktest.assertEQ(passedCounter, expectedPassedTest)
  return 0;
}

{% if item.init_object_default is defined %}
function testDefaultConstructor() : boolean {
   let actual : {{.item.object_type}} = new {{.item.object_type}}();
   if ({{.item.verify_test_result_function}}(actual,  {{.item.expected_default_test_data}})) {
     return true
   } else {
     return false
  }
}
{%- endif %}

function testConstructor(initDataIdx : int) : boolean {
    let result : boolean = false;
{%- if item.init_object_copy_constructor is defined %}
    let resultCopy : boolean = false;
{% endif %}
{%- for number in item.init_object_param_list.keys() %}
{%- if item.init_object_param_nature[number] == "object" %}
    let {{.number}} : {{.item.init_object_param_types[number]}} = new {{.item.init_object_param_types[number]}}(TEST_DATA_{{.number|upper}}[initDataIdx]);
{%- else %}
    let {{.number}} : {{.item.init_object_param_types[number]}} = TEST_DATA_{{.number|upper}}[initDataIdx];
  {%- endif %}
   // console.println();
   // console.print("{{.number}}:");
   // console.print({{.number}});
   // console.print(";");
{%- endfor %}
    let actual : {{.item.object_type}} = new {{.item.object_type}}({{.item.init_object_param_list.keys()|join(', ')}});
   // console.print("actual:");
   // console.print(actual);
   // console.print(";");
{%- if item.init_object_copy_constructor is defined %}
    let object4Copy : {{.item.object_type}} = new {{.item.object_type}}({{.item.init_object_param_list.keys()|list|join(', ')}});
    let actualClone : {{.item.object_type}} = new {{.item.object_type}}(object4Copy);
    // console.print("actualClone:");
    // console.print(actualClone.unboxed());
    // console.print(";");
    if ({{.item.verify_test_result_function}}(actualClone,  TEST_DATA_EXPECTED[initDataIdx])) {
      resultCopy = true
    }
{%- endif %}
    if ({{.item.verify_test_result_function}}(actual,  TEST_DATA_EXPECTED[initDataIdx])) {
      result = true
    }
{%- if item.init_object_copy_constructor is defined %}
    return (result && resultCopy)
{% else %}
    return result
{%- endif %}
}
